#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  int n;
  while (cin >> n && n) {
    ll ans = 0;
    stack<pair<ll, ll>> s;  // h, w
    for (int i = 0; i <= n; ++i) {
      ll h;
      if (i != n) {
        cin >> h;
      } else {
        h = 0;
      }
      if (!s.empty() && h > s.top().first) {
        s.emplace(h, 1);
      } else {
        ll w = 0;
        while (!s.empty() && h <= s.top().first) {
          auto [hh, ww] = s.top();
          s.pop();
          w += ww;
          ans = max(ans, hh * w);
        }
        s.emplace(h, w + 1);
      }
    }
    cout << ans << endl;
  }
}
